package com.ruoyi.refund.service.impl;

import com.ruoyi.refund.domain.HouseRefundT;
import com.ruoyi.refund.mapper.HouseRefundTMapper;
import com.ruoyi.refund.service.IHouseRefundTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 缴费信息Service业务层处理
 * 
 * @author lijie
 * @date 2023-04-24
 */
@Service
public class HouseRefundTServiceImpl implements IHouseRefundTService
{
    @Autowired
    private HouseRefundTMapper houseRefundTMapper;

    /**
     * 查询缴费信息
     * 
     * @param costId 缴费信息主键
     * @return 缴费信息
     */
    @Override
    public HouseRefundT selectHouseRefundTByCostId(Long costId)
    {
        return houseRefundTMapper.selectHouseRefundTByCostId(costId);
    }

    /**
     * 查询缴费信息列表
     * 
     * @param houseRefundT 缴费信息
     * @return 缴费信息
     */
    @Override
    public List<HouseRefundT> selectHouseRefundTList(HouseRefundT houseRefundT)
    {
        return houseRefundTMapper.selectHouseRefundTList(houseRefundT);
    }

    /**
     * 批量删除缴费信息
     * 
     * @param costId,userName 需要删除的缴费信息主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteHouseRefundTByCostIds(Long costId, String userName, Date refundDate)
    {

            HouseRefundT houseRefundTVO = new HouseRefundT();
            houseRefundTVO = houseRefundTMapper.selectHouseRefundTByCostId(costId);
            if(houseRefundTVO.getBalance()<houseRefundTVO.getCostMoney()){
                return 2;
            }
            houseRefundTMapper.updateHouseCostRefundBatchT(houseRefundTVO);
            houseRefundTVO.setCostSts("2");
            houseRefundTVO.setCostWay("1");
            houseRefundTVO.setCheckSts("0");
            houseRefundTVO.setCostRefundId(String.valueOf(houseRefundTVO.getCostId()));
            houseRefundTVO.setCostMoney(-houseRefundTVO.getCostMoney());
            int costId1 = houseRefundTMapper.getCostId();
            houseRefundTVO.setSerial(String.valueOf(costId1+1));
            int costId2= Integer.parseInt((String.valueOf(costId1+1)));
            houseRefundTVO.setCreater(userName);
            houseRefundTVO.setRefundMoney(houseRefundTVO.getCostMoney());
            houseRefundTVO.setRefundDate(refundDate);
            houseRefundTMapper.insertHouseCostRefundBatchT(houseRefundTVO);
            houseRefundTMapper.updateHouseDoorBalanceT(houseRefundTVO);
            houseRefundTMapper.insertHouseRefundT(houseRefundTVO);
            return costId2;
    }

    @Override
    public HouseRefundT selectHouseRefundNote(Long costId) {
        return houseRefundTMapper.selectHouseRefundNote(costId);
    }
}
